<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/config.inc.php');
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/top.inc.php');

$course_id = mysql_real_escape_string(strip_tags($_POST['id']));
$subject_id = mysql_real_escape_string(strip_tags($_POST['sid']));
$course_number = mysql_real_escape_string(strip_tags($_POST['course_num']));
$course_name = mysql_real_escape_string(strip_tags($_POST['course_name']));
$hours_per_week = mysql_real_escape_string(strip_tags($_POST['credits']));
$graduate = mysql_real_escape_string(strip_tags($_POST['grad']));
$lab_id = mysql_real_escape_string(strip_tags($_POST['lab']));

$get_subject_data = mysql_query("SELECT * FROM course_subjects WHERE id = $subject_id");
$subject_name = mysql_result($get_subject_data,0,'subject_title');
$abbreviation = mysql_result($get_subject_data,0,'abbreviation');

echo "<h1>Edit Course for ".stripslashes($subject_name)."</h1>";

if ($lab_id)
{
	$query2 = "UPDATE courses 
				SET course_number='$course_number',
					course_subject_id='$subject_id',
					title='$course_name',
					hours_per_week='$hours_per_week',
					lab_number='$lab_id',
					graduate_level='$graduate'
				WHERE id='$course_id'";
}
else
{
	$query2 = "UPDATE courses 
				SET course_number='$course_number',
					course_subject_id='$subject_id',
					title='$course_name',
					hours_per_week='$hours_per_week',
					lab_number=NULL,
					graduate_level='$graduate'
				WHERE id='$course_id'";
}

$result2 = mysql_query($query2);

if ($result2)
{
	echo "<b>".stripslashes($abbreviation)." ".stripslashes($course_number)."</b> has been successfully updated!";
	echo "<br />";
}
else
{
	echo "<b>".stripslashes($abbreviation)." ".stripslashes($course_number)."</b> was NOT able to be updated at this time!";
	echo "<br />";
}

//close
mysql_close();

echo "<p>";
	echo "<a href='courses.php?id=$subject_id'>&lt;&lt; Back to Courses Portal</a><br />";
echo "</p>";

?>

<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/bottom.inc.php');
?>